Passed
Push — master ( e1efef...d34f83 )
by
unknown
15:24
created

MenuView   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 39
rs 10
wmc 5

3 Functions

Rating   Name   Duplication   Size   Complexity  
A destroy 0 3 1
A update 0 5 2
A constructor 0 9 2
1
class MenuView {
2
    /**
3
     * @param {[MenuItem]} items
4
     * @param {EditorView} editorView
5
     *
6
     * @return {void}
7
     */
8
    constructor(items, editorView) {
9
        this.items = items;
10
        this.editorView = editorView;
11
12
        this.dom = document.createElement('div');
13
        this.dom.className = 'menubar';
14
        items.forEach(menuItem => this.dom.appendChild(menuItem.render(editorView)));
15
        this.update(editorView);
16
    }
17
18
    /**
19
     * Called by Prosemirror when the state of the editor changes
20
     *
21
     * @param {EditorView} editorView
22
     *
23
     * @return {void}
24
     */
25
    update(editorView) {
26
        this.items.forEach((item) => {
27
            item.update(editorView);
28
        });
29
    }
30
31
    /**
32
     * Called by Prosemirror when the menu is removed
33
     *
34
     * @return {void}
35
     */
36
    destroy() {
37
        this.dom.parentNode.removeChild(this.dom);
38
    }
39
}
40
41
export default MenuView;
42